/*
 * main.cpp
 *
 *  Created on: Oct 14, 2013
 *      Author: javier
 */


#include "Interfaz/TableroSDL.h"
#include "Interfaz/Confite.h"
#include "Interfaz/Barrita.h"
#include "Interfaz/EstrellaDorada.h"
#include "Interfaz/CeldaSDL.h"
#include "Interfaz/MovementHandler.h"
#include "logica/Partida.h"
#include "SDL/SDL_mixer.h"
#include "SDL/SDL_ttf.h"
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "logica/Tablero.h"
#include "Conversor/Conversor.h"
#include "Client/StringInput.h"
#include "Client/Login.h"

using std::string;
using std::vector;
using std::cout;
using std::endl;

extern const unsigned int SIZECELDA = 64;
extern const unsigned int NUMFILAS = 10;
extern const SDL_Color textColor = {0, 0, 0};
const unsigned int NUMCOLS = 10;
const unsigned int CANTPLAYERS = 4;


void pruebaIntegracion(int argc, char** argv){
    Partida p;
    vector<CeldaBase*>* celdasBase;
    vector<CeldaSDL*> celdasVista;
    vector<string> nombres;
    nombres.push_back("Nacho");
    nombres.push_back("Javi");
    CeldaSDL* celda;
    Conversor c;
    unsigned int nFil, nCol;
    unsigned int counter = 0;
    p.validarTablero();
    celdasBase = p.getCeldas();
    TableroSDL tableroInterfaz(p.getFilas(), p.getColumnas());
	tableroInterfaz.init("Tablero");
	TTF_Init();
	tableroInterfaz.createPuntajes(2, tableroInterfaz.getAncho() - SIZEEXTRA + SIZEEXTRA/4, nombres);
	tableroInterfaz.setFondo("trunk/Imagenes/fondoJapones.png");
    for (vector<CeldaBase*>::iterator It = celdasBase->begin(); It != celdasBase->end(); ++It){
    	nFil = counter%p.getFilas();
    	nCol = counter/p.getColumnas();
    	celda = c.convertCelda(*It, nCol, nFil, counter);
    	celdasVista.push_back(celda);
    	counter++;
    }
    tableroInterfaz.setCeldas(celdasVista);
	bool quit = false;
	SDL_Event event;
//	Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096);
//	Mix_Music *music = NULL;
//	music = Mix_LoadMUS("trunk/Sonidos/musica.wav");
//	Mix_PlayMusic(music, -1);
	MovementHandler handler(&tableroInterfaz);
	handler.setPartida(&p);
    while(quit == false){
		//While there's an event to handle
		//SDL_WaitEvent() and SDL_PeepEvents() can be used too
    	tableroInterfaz.dibujar();
		while(SDL_PollEvent(&event)){
			//If the user has Xed out the window
			if(event.type == SDL_QUIT){
				//Quit the program
				quit = true;
			}else if(event.type == SDL_MOUSEMOTION){
				handler.ubicarMouse(event.motion.x, event.motion.y);
			}else if(event.type == SDL_MOUSEBUTTONDOWN){
				handler.pulsaGolosina();
			}else if(event.type == SDL_MOUSEBUTTONUP){
				tableroInterfaz.sumarPuntos(0, handler.soltarGolosina());
			}
		}
	}
//	Mix_FreeMusic( music );
//	Mix_CloseAudio();
	TTF_Quit();
	SDL_Quit();

}

void pruebaLogin1(){
	//Tamaño PantallaLogin
	TTF_Init();
	Login login;
	login.logInit();
    SDL_EnableUNICODE(SDL_ENABLE);
	bool quit = false;
	SDL_Event event;
	login.dibujar();
	while(quit == false){
		while(SDL_PollEvent(&event)){
			//If the user has Xed out the window
			if(event.type == SDL_QUIT){
				//Quit the program
				quit = true;
			}else if(event.type == SDL_KEYDOWN){
				login.handleInput(event);
			}else if(event.type == SDL_MOUSEMOTION){
				login.ubicarMouse(event.motion.x, event.motion.y);
			}else if(event.type == SDL_MOUSEBUTTONUP){
				login.handleClick();
			}
		}
		login.dibujar();
	}
	TTF_Quit();
    SDL_EnableUNICODE(SDL_DISABLE);
}



int main(int argc, char** argv) {
//	pruebaLogin1();
	pruebaIntegracion(argc, argv);
	return 0;
}
